﻿
@{
    var coverageid = (int)ViewBag.coveid;
    var coverage = (Fcom.VNInsurance.Web.Models.Coverage)ViewBag.coverage;
    ViewBag.Title = "Quản lý quyền lợi";
    Layout = "~/Views/Shared/_CpanelLayout.cshtml";
}

<link rel="stylesheet" href="@Url.Content("~/Content/jqwidgets/styles/jqx.base.css")" type="text/css" />
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcore.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdata.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxbuttons.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxscrollbar.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxmenu.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxcheckbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxlistbox.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxdropdownlist.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.sort.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.pager.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.selection.js")"></script> 
    <script type="text/javascript" src="@Url.Content("~/Content/jqwidgets/jqxgrid.edit.js")"></script> 
<script type="text/javascript">
        $(document).ready(function () {
           
            var url = "@Url.Action("getBenefitList", "Benefit", new { CoverageID=coverageid})";
            // prepare the data
            var source =
            {
                datatype: "json",
                datafields: [
                    { name: 'BenefitID', type: 'int' },
                    { name: 'LangID', type: 'string' },
                    { name: 'BenefitCoverageName', type: 'string' },
                    { name: 'BenefitEnadbleSub', type: 'bool' },
                    { name: 'BenefitEnableIsmoney', type: 'bool' },
                    { name: 'BenefitDisplay', type: 'string' },
                   { name: 'EnableChildBenefit', type: 'bool' },
                    { name: 'EnableNumJoin', type: 'bool' },
                     { name: 'EnableText', type: 'bool' },
                ],
                id: 'BenefitID',
                url: url
            };
           

            var dataAdapter = new $.jqx.dataAdapter(source, {
                downloadComplete: function (data, status, xhr) { },
                loadComplete: function (data) { },
                loadError: function (xhr, status, error) { }
            });
            // initialize jqxGrid
            $("#jqxgrid").jqxGrid(
            {
                width: 1150,
                source: dataAdapter,
                pageable: true,
                autoheight: true,
                sortable: true,
                altrows: true,
                enabletooltips: true,
                editable: true,
                selectionmode: 'multiplecellsadvanced',
                columns: [
                  { text: 'ID', datafield: 'BenefitID', width: 30 },
                   { text: 'Quyền Lợi', datafield: 'BenefitDisplay', width: 250 },
          
                  {
                     text: 'Chỉnh sửa', datafield: 'Edit', columntype: 'button', width: 100, cellsrenderer: function () {
                         return "Edit";
                     }, buttonclick: function (editrow) {

                         var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                         window.location = "@Url.Action("EditBenefit", "Benefit")/" + dataRecord.BenefitID;
                     }
                  },
                  {
                      text: 'Xóa', datafield: 'Xóa', columntype: 'button', width: 100, cellsrenderer: function () {
                          return "Xóa";
                      }, buttonclick: function (editrow) {

                          var dataRecord = $("#jqxgrid").jqxGrid('getrowdata', editrow);
                          var rr = confirm("Bạn có muốn xóa bài viết \"" + dataRecord.BenefitDisplay + "\" ?");
                          if (rr) {
                              $.ajax({
                                  type: "post",
                                  url: "@Url.Action("remove","Benefit")",
                                  data: { id: dataRecord.BenefitID },
                                  datatype: "json",
                                  success: function (rvdata) {
                                      if (rvdata) {
                                          $("#jqxgrid").jqxGrid({ source: dataAdapter });
                                      }
                                  }

                              });
                          }//end rr

                      }
                  }
                ]                
            });
        });
    </script>
<div class="container" style="padding:10px;">
    <fieldset>
                 <legend style="color:#a60002;">Quản lý Quyền lợi: @coverage.Name</legend>
   </fieldset>
   @Html.ActionLink("Back","Index","Coverage",null,null) |  @Html.ActionLink("Thêm quyền lợi","AddBenefit","Benefit",null,null)
    <br /><br />
   <div id="jqxgrid" class="container">

   </div>
</div>
